import 'package:animal/constant/color.dart';
import 'package:animal/constant/font.dart';
import 'package:animal/socket/socket_client.dart';
import 'package:animal/ui/friend/page/friend_list_page.dart';
import 'package:animal/ui/home/controller/home_index_controller.dart';
import 'package:animal/ui/message/page/message_list_page.dart';
import 'package:animal/ui/mine/page/mine_index_page.dart';
import 'package:animal/ui/goods/page/shop_mall_page.dart';
import 'package:animal/ui/shop_car/page/shop_car_page.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

///主页的底部Appbar
class HomeIndexPage extends StatefulWidget {
  const HomeIndexPage({Key? key}) : super(key: key);

  @override
  _HomeIndexPageState createState() => _HomeIndexPageState();
}

class _HomeIndexPageState extends State<HomeIndexPage> with SingleTickerProviderStateMixin {
  late HomeIndexController controller;

  late TabController tabController;

  int index = 0;

  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 5, vsync: this);
    tabController.addListener(() {
      setState(() {
        index = tabController.index;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    Get.put(ClientSocket());
    controller = Get.put(HomeIndexController());
    return Scaffold(
      body: TabBarView(controller: tabController, children: <Widget>[
        ShopMallPage(),
        FriendListPage(),
        const MessageListPage(),
        ShopCarPage(),
        const MineIndexPage(),
      ]),
      bottomNavigationBar: Container(
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(ScreenUtil().L(20)), topRight: Radius.circular(ScreenUtil().L(20))),
        border: Border.all(width: ScreenUtil().L(2), color: const Color(0X19B5B5B5))),
        child: TabBar(
          controller: tabController,
          unselectedLabelColor: Colors.black,
          labelColor: GFColors.PRIMARY,
          indicatorColor: Colors.transparent,
          indicatorSize: TabBarIndicatorSize.tab,
          tabs: [
            Tab(
              icon: Image.asset("images/home1${index == 0 ? "s" : ""}.png", width: ScreenUtil().L(30)),
              child: Text(
                '商城',
                style: KFontConstant.myTextStyle(size: 15, color: KColorConstant.black444),
              ),
            ),
            Tab(
              icon: Image.asset("images/home2${index == 1 ? "s" : ""}.png", width: ScreenUtil().L(30)),
              child: Text(
                '通讯录',
                style: KFontConstant.myTextStyle(size: 15, color: KColorConstant.black444),
              ),
            ),
            Tab(
              icon: Image.asset("images/home3${index == 2 ? "s" : ""}.png", width: ScreenUtil().L(30)),
              child: Text(
                '消息',
                style: KFontConstant.myTextStyle(size: 15, color: KColorConstant.black444),
              ),
            ),
            Tab(
              icon: Image.asset("images/home4${index == 3 ? "s" : ""}.png", width: ScreenUtil().L(30)),
              child: Text(
                '购物车',
                style: KFontConstant.myTextStyle(size: 15, color: KColorConstant.black444),
              ),
            ),
            Tab(
              icon: Image.asset("images/home5${index == 4 ? "s" : ""}.png", width: ScreenUtil().L(30)),
              child: Text(
                '我的',
                style: KFontConstant.myTextStyle(size: 15, color: KColorConstant.black444),
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    tabController.dispose();
    super.dispose();
  }
}
